home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / util / misc / Fudgit233.lha / Source / src / dl / dl_ldfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-14  |  2.7 KB  |  97 lines

  1. /***********************************************************
  2. Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  3. Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI not be used in advertising or publicity pertaining to
  13. distribution of the software without specific, written prior permission.
  14.  
  15. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  18. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /*
  25. ** dload1 - Dynamically load a file.
  26. */
  27.  
  28. #define _auxtemp _auxtemp3    /* Bug in ldfcn.h */
  29.  
  30. #include <stdio.h>
  31. #include <filehdr.h>
  32. #include <syms.h>
  33. #include <ar.h>
  34. #include <ldfcn.h>
  35. #include <aouthdr.h>
  36.  
  37. #include "dl.h"
  38.  
  39. #ifdef DEBUG
  40. #define D(x) (x)
  41. #else
  42. #define D(x)
  43. #endif /* DEBUG */
  44.  
  45. extern int dl_ldnfilep(struct ldfile*);
  46. extern int dl_ldzfilep(struct ldfile*, char *);
  47.  
  48. /*
  49. ** dl_ldfile - Load an incremental file.
  50. ** dl_ldfile determines wether to load a ZMAGIC file or something else
  51. ** and calls the appropriate routine to load it.
  52. */
  53. int
  54. dl_ldfile(char *fn)
  55. {
  56.     LDFILE *ldptr;
  57.     int rv;
  58.     AOUTHDR aouth;
  59.  
  60.     ldptr = ldopen(fn, NULL);
  61.     if ( ldptr == 0 ) {
  62.     dl_error(0, fn);
  63.     return 0;
  64.     }
  65.     /*
  66.     ** Unfortunately, the mld library doesn't provide us with the magic
  67.     ** number.
  68.     */
  69.     if ( ldohseek(ldptr) == FAILURE ) {
  70.     dl_error("Ill-formatted binary %s (cannot seek to header)", fn);
  71.     ldclose(ldptr);
  72.     return 0;
  73.     }
  74.     if (  FREAD((char *)&aouth, 1, sizeof(aouth), ldptr) != sizeof(aouth)) {
  75.     dl_error("Ill-formatted binary %s (cannot read)", fn);
  76.     D(printf("File-pos=%d\n", FTELL(ldptr)));
  77.     ldclose(ldptr);
  78.     return 0;
  79.     }
  80.     if ( aouth.magic == NMAGIC )
  81.       rv = dl_ldnfilep(ldptr);
  82.     else if( aouth.magic == ZMAGIC )
  83. #if 0
  84.       if ( getenv("DLDEBUG") == 0 )
  85.       rv = dl_ldnfilep(ldptr);     /* XXXX should be z */
  86.       else
  87. #endif
  88.       rv = dl_ldzfilep(ldptr, fn);
  89.     else {
  90.     dl_error("Not ZMAGIC or NMAGIC file: %s", fn);
  91.     rv = 0;
  92.     }
  93.     ldclose(ldptr);
  94.     return rv;
  95. }
  96.  
  97.